/* 
 * File:   Timer.cpp
 * Author: vikrantsingh
 * 
 * Created on 2 November, 2013, 10:17 PM
 */

#include "Timer.h"
#include <sstream>
#include <vector>
#include "../dependency/debug.h"
#include <sys/time.h>
#include <unistd.h>
void Timer::updateExecutionTime(double diff) {
    //printf("It took you %.2lf seconds to type your name.\n", diff);
    ostringstream mystream;
    mystream << "Query executed in ";
    mystream << diff << " secs" << endl;
    const char *var = mystream.str().c_str();
    strcpy(executionTime, var);
}

void Timer::updateNumberOfRows(int numOfRows) {
    ostringstream mystream;
    mystream << "Number of Rows= ";
    mystream << numOfRows << endl;
    const char *var = mystream.str().c_str();
    strcpy(numberOfRowsReturned, var);
}

void Timer::startTimer() {
    gettimeofday(&start, NULL);
}

void Timer::endTimer() {
    gettimeofday(&end, NULL);
    seconds = end.tv_sec - start.tv_sec;
    useconds = end.tv_usec - start.tv_usec;
    mtime = ((seconds) * 1000 + useconds / 1000.0) + 0.5;
    //printf("Elapsed time: %ld milliseconds\n", mtime);
}

string Timer::getElapsedTimeInSeconds() {
    ostringstream mystream;
    mystream << seconds;
    return mystream.str();
}

string Timer::getElapsedTimeInMilliSeconds() {
    ostringstream mystream;
    mystream << mtime;
    return mystream.str();
}

void Timer::updateExecutionTimeMessage(string msg) {
    strcpy(executionTime, msg.c_str());
}
